package cn.topevery.garden.dal.logic;

import cn.topevery.garden.dal.dao.ProjectFileDao;
import cn.topevery.garden.entity.po.ProjectFile;
import cn.topevery.garden.entity.query.ProjectFileQuery;
import cn.topevery.garden.framework.base.BaseLogic;
import hw.topevery.framework.db.base.BaseEntityDao;
import hw.topevery.framework.db.entity.DataPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 描述 The type Project file logic.
 *
 * @author code -generate
 * @created 2021 -09-01 09:34:05
 * @date 2021 -09-01
 */
@Service
public class ProjectFileLogic extends BaseLogic<ProjectFile> {
    /**
     * The Project file dao.
     */
    @Autowired
    ProjectFileDao projectFileDao;

    /**
     * 描述 Gets dao.
     *
     * @return the dao
     * @author wenzhao.lin
     * @created 2021 -09-01 09:34:05
     */
    @Override
    public BaseEntityDao<ProjectFile, Integer> getDao() {
        return projectFileDao;
    }


    /**
     * 获取列表
     *
     * @param query the query
     * @return the data pager
     * @author wenzhao.lin
     * @created 2021 -09-01 09:34:05 List page data pager.
     */
    public DataPager<ProjectFile> listPage(ProjectFileQuery query) {
        return projectFileDao.listPage(query);
    }

    /**
     * 根据自增id批量删除
     *
     * @param userId the user id
     * @param ids    the ids
     * @author wenzhao.lin
     * @created 2021 -09-01 09:34:05 Delete batch by id.
     */
    public void deleteBatchById(String userId,Integer[] ids) {
        projectFileDao.delete(userId, ids);
    }

    /**
     * 根据自增id保存或者更新
     *
     * @param userId          the user id
     * @param pid             the pid
     * @param projectFileList 实体
     * @author wenzhao.lin
     * @created 2021 -09-01 09:34:05 Save or update.
     */
    public void saveOrUpdate(String userId, Integer pid, List<ProjectFile> projectFileList,Integer type){
        projectFileDao.deleteById(pid);
        for(ProjectFile projectFile : projectFileList){
            projectFile.setMainId(pid);
            projectFile.setType(type);
            projectFileDao.saveOrUpdate(userId,projectFile);
        }
    }

    /**
     * 描述 通过pid获取列表.
     *
     * @param pid the pid
     * @return the list
     * @author wenzhao.lin
     * @created 2021 -09-01 09:34:05 Get list by pid list.
     */
    public List<ProjectFile> getListByPid(Integer pid,Integer type){
        return projectFileDao.getListByPid(pid, type);
    }

    /**
     * 描述 通过pid删除.
     *
     * @param id the id
     * @author wenzhao.lin
     * @created 2021 -09-01 09:34:05 Delete by id.
     */
    public void deleteById(Integer id){
        projectFileDao.deleteById(id);
    }
}
